using System;
using L=Science.Physics.GeneralPhysics;

namespace Serway.Chapter33
{
	/// <summary>
	/// Example05: Analyzing a Series RLC Circuit
	/// A series RLC AC circuit has R = 425 \Omega, 
	/// L = 1.25 H, C = 3.50 \mu F, \omega = 377 s^{-1}, 
	/// and \Delta V_{max} = 150 V.
	/// (A)	Determine the inductive reactance, the capacitive 
	/// reactance, and the impedance of the circuit.
	/// (B)	Find the maximum current in the circuit.
	/// (C)	Find the phase angle between the current and voltage.
	/// (D)	Find both the maximum voltage and the instantaneous 
	/// voltage across each element.
	/// </summary>
	public class Example05
	{
		public Example05()
		{
		}
		private string result;
		public string Result
		{
			get{return result;}
		}
		public void Compute()
		{
			L.Resistance R = new L.Resistance();
			R.Ohm = 425.0;
			L.Inductance LL = new L.Inductance();
			LL.H = 1.25;
			L.Capacitance C = new L.Capacitance();
			C.F = 3.5E-6;
			L.Frequency f = new L.Frequency();
			f.Hz = 377.0/2/Math.PI;
			L.ElectricPotentialDifference V
				= new L.ElectricPotentialDifference();
			V.V = 150.0;
			L.CircuitRLC cir = new L.CircuitRLC(R,LL,C);
			//(A)
			result+=Convert.ToString(LL.Reactance(f))+"\r\n";      
			result+=Convert.ToString(C.Reactance(f))+"\r\n";   
			result+=Convert.ToString(cir.Impedance(f))+"\r\n";   
			//(B)
			L.ElectricCurrent I = new L.ElectricCurrent();
			I.A = V.V/cir.Impedance(f);
			result+=Convert.ToString(I.A)+"\r\n";   
			//(C)
			result+=Convert.ToString(cir.PhaseAngle(f)*180.0/Math.PI)+"\r\n";   
			//(D)
			L.ElectricPotentialDifference VR = new L.ElectricPotentialDifference();
			VR.V = I.A*R.Ohm;
			result+=Convert.ToString(VR.V)+"\r\n";   
			L.ElectricPotentialDifference VL = new L.ElectricPotentialDifference();
			VL.V = I.A*LL.Reactance(f);
			result+=Convert.ToString(VL.V)+"\r\n";   
			L.ElectricPotentialDifference VC = new L.ElectricPotentialDifference();
			VC.V = I.A*C.Reactance(f);
			result+=Convert.ToString(VC.V)+"\r\n";   
		}
	}
}
